package com.zhuiyun.educations.api.subject.controller;

import com.zhuiyun.educations.api.subject.entity.Subject;
import com.zhuiyun.educations.api.subject.service.SubjectService;
import com.zhuiyun.educations.common.response.CommonResult;

import com.zhuiyun.educations.util.pageUtil.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName SubjectController
 * @Description TODO 科目信息控制层
 * @Author 杨友朋
 * @Date 2023/6/19 15:10
 **/
@RestController
@CrossOrigin
@RequestMapping("/subject")
public class SubjectController {
    @Resource
    SubjectService subjectService;

    /**
    * @Author 杨友朋
    * @Description TODO 分页全查父级科目
    * @Date 2023/6/20 8:32
    * @Return CommonResult
    * @param subject,pageRequest
    */
    @GetMapping("/selectSubject")
    public CommonResult selectSubject(Subject subject, PageRequest pageRequest){
        return CommonResult.ok(subjectService.selectSubject(subject,pageRequest));
    }

    /**
    * @Author 杨友朋
    * @Description TODO 全查父级科目
    * @Date 2023/6/21 20:26
    * @Return CommonResult
    * @param subject
    */
    @GetMapping("/selectAll")
    public CommonResult selectAll(Subject subject){
        return CommonResult.ok(subjectService.selectAll(subject));
    }


    /**
    * @Author 杨友朋
    * @Description TODO 添加父级科目
    * @Date 2023/6/21 20:28
    * @Return CommonResult
    * @param subject
    */
    @PostMapping("/insertSubject")
    public CommonResult insertSubject(@RequestBody Subject subject){
        return subjectService.insertSubject(subject);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据id删除父级科目
    * @Date 2023/6/21 20:29
    * @Return CommonResult
    * @param id
    */
    @GetMapping("/delSubjectById")
    public CommonResult delSubjectById(Integer id){
        return subjectService.deleteSubjectById(id);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据ids批量删除父级科目
    * @Date 2023/6/21 20:30
    * @Return CommonResult
    * @param ids
    */
    @PostMapping("/delSubjectByIds")
    public CommonResult delSubjectByIds(@RequestBody List<Integer> ids){
        return subjectService.deleteSubjectByIds(ids);
    }

}
